<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let data = {
        name: "尚硅谷",
        address: "武汉",
      };

      let obs = new Server(data);
      let vm = {};
      vm._data = data = obs;
      function Server(obj) {
        let keys = Object.keys(obj);
        keys.forEach((k) => {
          Object.defineProperty(this, k, {
            get() {
              console.log(k + "被访问了");
              return obj[k];
            },
            set(val) {
              console.log(k + "被修改了，我要去生成虚拟dom，进行算法比较");
              obj[k] = val;
            },
          });
        });
      }
    </script>
  </body>
</html>
